//
//  MXGamePopupViewItemCell.swift
//  d11
//
//  Created by peale_pro on 2019/7/16.
//  Copyright © 2019年 Tech_001. All rights reserved.
//

import UIKit

class MXGamePopupViewItemCell: UICollectionViewCell {
    var bgImgView: UIImageView?
    var topImgView: UIImageView?
    override init(frame:CGRect){
        super.init(frame: frame)
        setUpUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpUI() -> Void {
        self.bgImgView = UIImageView.init()
        self.contentView.addSubview(self.bgImgView!)
        self.bgImgView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview()
            make.height.equalToSuperview()
            make.centerX.equalToSuperview()
        }
        
        self.topImgView = UIImageView.init()
        self.topImgView?.image = imageNamed("icon_home_whz")
        self.contentView.addSubview(self.topImgView!)
        self.topImgView?.snp.makeConstraints{(make) in
            make.width.equalTo(72)
            make.height.equalTo(60)
            make.right.equalToSuperview().offset(-3)
            // make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(1)
        }
    }
    func setData(imgUrl:String,gameId:String,gameCount:Int) -> Void {
        let hallDict = getHall(withId: gameId)
        let status = hallDict?["status"] as? Int ?? -1
        self.topImgView?.isHidden = true
        if status == 0{
            self.topImgView?.isHidden = false
        }
        
        if gameCount == 1{
            self.bgImgView?.sd_setImage(with: URL(string: imgUrl), placeholderImage: imageNamed("icon_newhome_game_zwt_bg_one_ipad"), options: .refreshCached, completed: nil)
        }else if gameCount == 2{
            self.bgImgView?.sd_setImage(with: URL(string: imgUrl), placeholderImage: imageNamed("icon_newhome_game_zwt_bg_max_ipad"), options: .refreshCached, completed: nil)
        } else
        {
            self.bgImgView?.sd_setImage(with: URL(string: imgUrl), placeholderImage: imageNamed("icon_newhome_game_zwt_bg_ipad"), options: .refreshCached, completed: nil)
        }
        
    }
    
    func getHall(withId: String?) -> [String:Any]? {
        if let hallInfoData = GlobalInfo.hallInfoData {
            for hall in hallInfoData {
                let id = hall["id"] as? String ?? "0"
                if id == withId {
                    return hall
                }
            }
        }
        return nil
    }
}
